package com.liqiye.paymanager.controller;

import com.liqiye.paymanager.bean.order.CreateOrderRequest;
import com.liqiye.paymanager.entity.Order;
import com.liqiye.paymanager.service.common.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/list")
    public List<Order> list() {
        return orderService.selectAll();
    }

    @PostMapping("/insert")
    public ResponseEntity<?> insert() {
        Order order = new Order();
        order.setName("订单-" + Math.random());
        orderService.insert(order);
        return ResponseEntity.ok(order);
    }

    @PostMapping("/create")
    public ResponseEntity<?> create(@RequestBody CreateOrderRequest req) {
        orderService.create(req);
        return ResponseEntity.ok("success");
    }

    @PostMapping("/delete")
    public ResponseEntity<?> delete(String id) {
        orderService.deleteById(id);
        return ResponseEntity.ok("success");
    }

}
